<template>
  <article class="page">
    <headerbar>统计分析</headerbar>
    <section class="frame-content-sub no-bg">
      <ul class="top-menu">
        <li @click="clickNav('1')" :class="{'active':routeName == '1'}"><span>培训机构</span></li>
        <li @click="clickNav('2')" :class="{'active':routeName == '2'}"><span>学员</span></li>
        <li @click="clickNav('3')" :class="{'active':routeName == '3'}"><span>教师</span></li>
        <li @click="clickNav('4')" :class="{'active':routeName == '4'}"><span>主办单位</span></li>
      </ul>

      <section class="inner-content pdv-9 pdh-4">

        <section class="list-news-img bg-white">
          <section class="d-scroll-2head ">
            <cube-scroll
              ref="scroll"
              :options="options"
              @pulling-up="onPullingUp"
            >

              <section v-for="item in list" class="appraise-item">
                <div v-if="routeName == '1'" class="name">{{item.institutionsName}}</div>
                <div v-if="routeName == '2'" class="name">{{item.userName}}</div>
                <div v-if="routeName == '3'" class="name">{{item.lecturerName}}</div>
                <div v-if="routeName == '4'" class="name">{{item.zbdwName}}</div>
                <div class="cont">
                  <div class="tip">
                    <span class="score-name">得分：</span>
                    <span class="score">{{item.score}}分</span>
                  </div>
                  <div @click="appraiseDetail(item, routeName)" class="btn">查看详情</div>
                </div>
              </section>

              <div class="text-center no-data" v-if="list.length===0">
                <img src="../../../../static/images/no_data.png" alt="">
                <p>暂无数据</p>
              </div>

            </cube-scroll>
          </section>
        </section>

      </section>

    </section>
  </article>
</template>

<script>
  export default {
    name: 'appraiseManage',
    data () {
      return {
        routeName: '1',
        pageIndex: 1,
        pageSize: 10,
        fetchNames: {
          1: 'findCountOfPxjg',
          2: 'findCountOfXy',
          3: 'findCountOfJsjkc',
          4: 'findCountOfZbdw'
        },
        list: [],
        options: {
          pullUpLoad: true,
          scrollbar: false
        }
      }
    },
    created () {
      let index = this.$route.query.index || 1
      this.clickNav(index)
    },
    methods: {
      clickNav (index) {
        if (this.$route.query.index !== index) {
          this.$router.replace({path: this.$route.name, query: {index: index}})
        }
        this.routeName = index
        this.pageIndex = 1
        this.list = []
        this[this.fetchNames[index]]().then(res => {
          if (res.data.length === 0) {
            this.tools.tip('已无更多数据')
          }
        })
      },
      appraiseDetail (item, index) {
        this.$store.statisticalAnalysisDetail = item
        this.$router.push({path: '/statisticalAnalysisDetail', query: {index: index}})
      },
      findCountOfJsjkc () {
        let params = {
//          "curriculumName": "1",
//          "jssj": "1",
//          "kssj": "1",
//          "lecturerId": "",
//          "lecturerName": "1",
          "limit": this.pageSize,
          "page": this.pageIndex
        }
        return this.fetchService.findCountOfJsjkc(params).then(res => {
          console.log(res)
          if (res.code !== 0) {
            return this.tools.tip(res.message || '获取数据失败')
          }
          this.$refs.scroll.forceUpdate && this.$refs.scroll.forceUpdate(true, false)
          this.list = this.list.concat(res.data)
          return res
        })
      },
      findCountOfPxjg () {
        let params = {
//          "curriculumName": "1",
//          "jssj": "1",
//          "kssj": "1",
//          "lecturerId": "",
//          "lecturerName": "1",
          "limit": this.pageSize,
          "page": this.pageIndex
        }
        return this.fetchService.findCountOfPxjg(params).then(res => {
          console.log(res)
          if (res.code !== 0) {
            return this.tools.tip(res.message || '获取数据失败')
          }
          this.$refs.scroll.forceUpdate && this.$refs.scroll.forceUpdate(true, false)
          this.list = this.list.concat(res.data)
          return res
        })
      },
      findCountOfXy () {
        let params = {
          type: 4,
          "limit": this.pageSize,
          "page": this.pageIndex
        }
        return this.fetchService.findCountOfXy(params).then(res => {
          console.log(res)
          if (res.code !== 0) {
            return this.tools.tip(res.message || '获取数据失败')
          }
          this.$refs.scroll.forceUpdate && this.$refs.scroll.forceUpdate(true, false)
          this.list = this.list.concat(res.data)
          return res
        })
      },
      findCountOfZbdw () {
        let params = {
          "limit": this.pageSize,
          "page": this.pageIndex
        }
        return this.fetchService.findCountOfZbdw(params).then(res => {
          console.log(res)
          if (res.code !== 0) {
            return this.tools.tip(res.message || '获取数据失败')
          }
          this.$refs.scroll.forceUpdate && this.$refs.scroll.forceUpdate(true, false)
          this.list = this.list.concat(res.data)
          return res
        })
      },
      onPullingUp () {
        this.pageIndex ++
        this[this.fetchNames[this.routeName]]().then(res => {
          if (res.data.length === 0) {
            this.tools.tip('已无更多数据')
          }
          setTimeout(() => {
            this.$refs.scroll.forceUpdate && this.$refs.scroll.forceUpdate(true, false)
          })
        })
      }
    }
  }
</script>

<style scoped>

</style>
